<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>悠悠有品</title>

    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/1.css') }}">

    <style>
        .center {
            background-image: url(../static/imgs/index.jpg);
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            min-height: 1000px;
        }
    </style>
</head>
<body>
<div class="head">
    <ul class="nav nav-pills">
        <li class="nav-item">
            <a class="nav-link" href="http://127.0.0.1:5000/index/">首页</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="http://127.0.0.1:5000/sp/">商品</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="http://127.0.0.1:5000/sell/">我也要卖</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="http://127.0.0.1:5000/buyAdmin/">我的购买</a>
        </li>
        {% if user %}
            <li class="nav-item">
                <a class="nav-link" href="http://127.0.0.1:5000/admin/">我发布的商品</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="http://127.0.0.1:5000/logout/">注销</a>
            </li>
        {% else %}
            <li class="nav-item">
                <a class="nav-link" href="http://127.0.0.1:5000/login/">登录</a>
            </li>
        {% endif %}

    </ul>


</div>

<div class="center">
    {% for goods in goodss %}
        <div class="center-item">
            <div class="card" style="width: 18rem;">
                <img src="{{ goods.img }}" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">{{ goods.g_name }}</h5>
                    <p class="card-text">
                        {{ goods.describe }}
                    </p>
                    <a href="#" class="btn btn-primary">价格：{{ goods.price }}</a>
                    <a href="#" class="btn btn-primary" aid="{{ goods.g_id }}">删除</a>
                </div>

            </div>
        </div>
    {% endfor %}
</div>
</body>

<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
    $(function () {
        $('.card-body a').click(function () {
            var thar = $(this);
            var g_id = thar.attr('aid');
            if (event.srcElement.outerText == "删除") {
                if (window.confirm("此操作不可逆，是否确认？")) {
                    $.post('/del/', {'g_id': g_id}, function (data) {
                        console.log(data.msg)
                        if (data.code==200){
                            location.reload()
                        }else{
                            alert(data.msg)
                        }
                    })

                }

            }
        })

    });
</script>

</html>